<?php
class Editor {
	private $_aObject;
	private $_oObject;
	
	public function __construct() {
		// TODO 增加判断编辑器是否存在
		$this->create ();
	}
	
	public function create() {
		$sPath = realpath ( ROOT . '/' . Base::getConf ( 'editor.path' ) );
		require_once $sPath . '/fckeditor.php';
		$this->_oObject = new FCKeditor ();
		$this->_oObject->BasePath = Base::getWebRelativePath ( $sPath ) . '/';
		$sLang = Base::getConf ( 'editor.lang' );
		if ($sLang) {
			self::setConfig ( 'AutoDetectLanguage', false );
			self::setConfig ( 'DefaultLanguage', $sLang );
		}
		return $this->_oObject;
	}
	
	public function setName($sName, $oObject = null) {
		if (is_object ( $oObject )) {
			$this->_oObject = $oObject;
		}
		$this->_oObject->InstanceName = $sName;
	}
	
	public function setConfig($sName, $sValue, $oObject = null) {
		if (is_object ( $oObject )) {
			$this->_oObject = $oObject;
		}
		$this->_oObject->Config [$sName] = $sValue;
	}
	
	public function set($sName, $sValue, $oObject = null) {
		if (is_object ( $oObject )) {
			$this->_oObject = $oObject;
		}
		$this->_oObject->$sName = $sValue;
	}
	
	public function getHtml($sName = null, $oObject = null) {
		if (is_object ( $oObject )) {
			$this->_oObject = $oObject;
		}
		if ($sName != null) {
			self::setName ( $sName );
		}
		return $this->_oObject->CreateHtml ();
	}
}
?>